﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Threading;
using System.Globalization;

public partial class ProductTypes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
               
                

            }
        }
    }

    protected void edit_Click(object sender, EventArgs e)
    {
        LinkButton lk = (LinkButton)sender;
        ViewState["aoe"] = lk.ToolTip;
        paidfees.Text = ((Label)lk.NamingContainer.FindControl("paidfees")).Text;
        
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }
    protected void delete_Click(object sender, EventArgs e)
    {

        LinkButton lk = (LinkButton)sender;
        string bb=((Label)lk.NamingContainer.FindControl("paidfees")).ToolTip;
        if ( bb== "0")
        {
            DB.DELETE("product_types", "int,id," + lk.ToolTip);
            GridView1.DataBind();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "alert('لا يمكن المسح حيث انه مرتبط بمنتجات');", true);

        }
    }
    protected void save_Click(object sender, EventArgs e)
    {
        //////////////////////////////////////////////
        List<string> fields = new List<string>();
        ArrayList values = new ArrayList();
        List<string> types = new List<string>();
        ///////////////
       
        /////////////////
        fields.Add("product_type");
        types.Add("string");
        values.Add(paidfees.Text);
        /////////////////////////////////////////////////
        fields.Add("tag");
        types.Add("string");
        values.Add(DropDownList1.SelectedValue);
       
        //////////////////////////////////
        if (ViewState["aoe"].ToString() == "0")
        {
            DB.INSERT("product_types", fields, types, values);
        }
        else
        {
            DB.UPDATE("product_types", "int,id," + ViewState["aoe"].ToString(), fields, types, values);

        }
        ViewState["aoe"] = 0;
        GridView1.DataBind();

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lb = (Label)e.Row.FindControl("startofsub");
            lb.Text = (lb.Text == "020" ? "غير متكرر" : "متكرر");
            //string vv = ().Text;
            //DateTime ff = DateTime.Parse(vv);
            //LinkButton lk = (LinkButton)e.Row.FindControl("edits");
            //if (ff > DateTime.Now)
            //{

            //    lk.Enabled = true;

            //    // Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
            //}
            //else
            //{

            //    lk.Text = "منتهى";
            //}


        }
    }
    protected void newsub_Click(object sender, EventArgs e)
    {
        ViewState["aoe"] = 0;
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }

}
